package org.example.entity.dto;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.example.entity.ProjectVersionTranslateDetail;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;


@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class TranslateCompareDto implements Serializable {

    private String targetLanguage;

    private String translation;

    public static JSONArray form(List<ProjectVersionTranslateDetail> projectVersionTranslateDetails){
        List<TranslateCompareDto> collect = projectVersionTranslateDetails.stream().map(p -> TranslateCompareDto.builder().translation(p.getTranslation()).targetLanguage(p.getTargetLanguage()).build()).collect(Collectors.toList());
        return JSONArray.parseArray(JSONObject.toJSONString(collect));
    }
}
